<template>
	<div>
		<van-nav-bar
		  left-arrow
		  @click-left="onClickLeft"
		  :border="false"
		>		
		  <van-icon name="arrow-left" slot="left" color="#000" size="20"/>
		  <div slot="title" class="weight_header">
		  	我发布的
		  </div>
		  <div slot="right" @click="link('/market/list/offBaby')">下架宝贝</div>
	   </van-nav-bar>		
	   
	   
	   <div class="noData" v-if="showNoData">
	   	<img src="../../../../static/img/lanhu/noData.png" alt="" />
	   </div>
	   
	   
		<van-pull-refresh v-model="refreshing" @refresh="onRefresh" v-if="!showNoData">
		  <van-list
		    v-model="loading"
		    :finished="finished"
		    :finished-text="finishedText"
		    @load="onLoad"
		    :immediate-check="false"
		    :style="{minHeight: clientHeight + 'px' }"
		  >		  
		    <div class="li" v-for="(item,index) in releaseList" :key="index" v-if="item.isShow">
		    	<div class="left imgWrap" :style="{backgroundImage: 'url(' + item.goodsImage + ')'}" @click="linkPreview(item)">
		    		<!--<img :src="item.goodsImage" alt="" />-->
		    	</div>
		    	<div class="right">
		    		<div class="title">{{item.comName}}</div>
		    		<div class="price">¥ {{item.comPrice}}</div>
		    		<div class="oi">
		    			<span>留言 {{item.disscount}}</span>
		    			<span style="margin-left: 15px;">浏览 {{item.history}}</span>
		    		</div>
		    		<div class="btn" style="border-bottom: 1px solid #f0f0f0;padding-bottom: 10px;">
		    			<!--<div @click="price(item,index)">降价</div>-->
		    			<div @click="polish(item)">擦亮</div>
		    			<div @click="edit(item)">编辑</div>
		    			<div @click="showMore(item,index)">...</div>
		    		</div>
		    	</div>
		    </div>		  
		  </van-list>		  
		</van-pull-refresh> 		
		  
        <van-popup v-model="showMoreWin">
        	<div class="showMoreWin">
				<van-cell-group>
				  <van-cell title="分享商品" @click="showShare"/>
				  <van-cell title="下架宝贝" @click="lower"/>
				  <van-cell title="删除商品" @click="del"/>
				  <van-cell title="取消"  @click="showMoreWin=false"/>
				</van-cell-group>        		
        	</div>
        </van-popup>
        <confirm ref="confirm1" @queryConfirm="queryConfirm1" title="确定下架该宝贝吗?"></confirm>  
        <confirm ref="confirm2" @queryConfirm="queryConfirm2" title="确定删除该商品吗?"></confirm>  
       
      
       <floor37 ref="floor37" @confirm="updatePrice"></floor37>
       
       <share ref="share" :data="currentData"></share>
	</div>	
</template>

<script>	
import share from '_c/share3.vue'	
import Floor37 from '_c/market/floor/floor37.vue'		
import confirm from '_c/confirm.vue'
import {getFun} from '@/api/publicFun.js'	 
let publicFun=getFun()	
export default {
	components: {
	    Floor37,confirm,share
	},		
	data() {
       return { 
       	  loading: false,    // 是否处于数据加载状态 
	      finished: false,   // 是否处于数据最底部的状态 
	      refreshing: false, // 是否处于下拉刷新状态         
          pageNum:1,         // 当前数据的页码数
          pages:0,           // 储存数据的最大页码数
          showMoreWin:false,  // 显示...弹框            
          url1:this.$api+'/marketorderservice/api/v1/market/findReleaseList',  // 发布列表
          url2:this.$api+'/marketorderservice/api/v1/market/deleteGoods/', //删除商品
          url3:this.$api+'/marketorderservice/api/v1/market/cancelGoods/', //下架商品
          url5:this.$api+'/marketorderservice/api/v1/market/updateGoodsUpdateTime', // 擦亮商品
          releaseList:[],     // 发布列表
          currentData:{},     // 记录选中的当前数据
          currentDataIndex:'', // 记录当前选中数据的索引
          showNoData:false,// 是否显示暂无数据
          finishedText:''   
       }
	},
	methods: {
	   	
	   polish(item){
	   	    let that=this	   	    
	        this.$Axios2.Get(this.url5+'/'+item.comId).then(function(res){
		   	 	if(res.data.flag){
		   	 		that.$toast('宝贝已擦亮')
		   	 	}else{
		   	 		that.$toast('宝贝今天已擦亮,请明天再来')
		   	 	}
		   	})	   	
	   },
	   // 跳转到商品详情页
	   linkPreview(item){
  			let arg='[{"comId":"'+item.comId+'"}]' 
  			this.link('/market/goods/preview',arg)			
	   },	
	   // 下架宝贝确认	
	   queryConfirm1(){	   	 
	   	 let that=this
	   	 this.$Axios2.Get(this.url3+this.currentData.comId).then(function(res){
	   	 	that.releaseList[that.currentDataIndex].isShow=false
	   	 })
	   },
	   // 删除商品确认
	   queryConfirm2(){
	   	 let that=this
	   	 this.$Axios2.Get(this.url2+this.currentData.comId).then(function(res){
	   	 	that.releaseList[that.currentDataIndex].isShow=false
	   	 })
	   },
	   // 打开价格编辑框
	   price(item,index){
	   	 this.$refs.floor37.showWin(item,index)
	   },
	   // 确认价格
	   updatePrice(obj,index){
	      this.releaseList[index].comPrice=obj.comPrice
	      this.releaseList[index].comOriginalprice=obj.comOriginalprice
	      this.releaseList[index].comIspost=obj.comIspost
	      this.releaseList[index].freight=obj.freight	      
	   },
	   showShare(){
	   	 this.showMoreWin=false
		 this.$refs.share.show()
	   },
	   // 点击 ... 后 下架宝贝操作
	   lower(){
	   	this.showMoreWin=false
        this.$refs.confirm1.showWin()  
	   },
	   // 点击 ... 后 删除宝贝操作
	   del(){
	   	this.showMoreWin=false
	   	this.$refs.confirm2.showWin()
	   },	   	
	   // ...操作	
	   showMore(item,index){
	   	 this.currentData=item
	   	 this.currentDataIndex=index
	   	 this.showMoreWin=true
	   },
	   // 编辑按钮
	   edit(item){
	   	 let arg='[{"comId":"'+item.comId+'"},{"backType":"3"}]' 
		 this.link('/market/goods/release',arg)	   	 	   	 
	   },
	   // 下拉刷新函数	
	   onRefresh() {
		  setTimeout(() => {
	          this.pageNum=1
	          this.releaseList=[]
	          this.getData()	
	          this.finished = false;
	          this.loading=false
			  this.refreshing = false;
		  }, 1000);          
	   },
	   // 上拉加载函数
	   onLoad(){	   	 
		 setTimeout(() => {		 	
	        if (this.refreshing) {
	          this.releaseList = [];
	          this.refreshing = false;
	        }
	        this.getData()
	      }, 1000);   	
	   },		
       // 获取数据
       getData(){
		  let that=this
		  let params={
		  	userId:this.userId
		  }
		  this.$Axios2.postRequest(this.url1,params,{pageNum:this.pageNum,pageSize:'10'}).then(function(res) {
		  	if(res.data.page.total==0){
		  		that.showNoData=true
		  		return false
		  	}
            if(that.pageNum>res.data.page.pages){
            	that.finishedText='我也是有底线的' 
            	that.finished = true;
            	return false
            }else{
			   for(var i=0;i<res.data.page.records.length;i++){
			  		res.data.page.records[i].isShow=true
			   }
	           that.releaseList=that.releaseList.concat(res.data.page.records)
	           that.pageNum++   //  下一次请求的时候页码加1	             	
	           that.loading = false;   // 关闭加载中
	           that.finished = false;  // 数据加载未完成	                    	
            }            
		  })	      	
       }
	},
	mixins:[publicFun],	
	mounted() {
	    this.userId=this.$router.currentRoute.query.userId;
	    this.backType=this.$router.currentRoute.query.backType;
	    this.getData()
	}
}	
</script>

<style scoped="" lang="scss">
*{color: #333;}
.van-nav-bar{background: #FFD630;}
.li{padding: 20px 20px 10px;display: flex;
   .left{img{width: 92px;height: 92px;display: block;border-radius: 2px;}}
   .right{margin-left: 15px;flex: 1;
       .title{font-size: 15px;font-weight:bold;display: -webkit-box;-webkit-box-orient: vertical;-webkit-line-clamp: 1;overflow: hidden;}
       .price{color: $fc1;margin: 14px 0;font-size: 14px;}
       .oi{span{color: $fc2;}}
       .btn{display: flex;justify-content: flex-end;margin-top: 10px;
          div{padding: 4px 12px;border:1px solid $bc1;margin-right: 9px;font-size: 13px;}
          div:nth-child(3){margin-right: 0;}
       }
   }
}
.imgWrap{width: 92px;height: 92px;overflow: hidden;background-repeat: no-repeat;background-size:cover;background-position: 50% 50%;border-radius: 4px;}
.li.active{border-bottom: none;}
.showMoreWin{width: 300px;background: #fff;}


.moreShareWrap{padding: 20px 15px 0;display: flex;
     .item{display: flex;flex-direction: column;margin-right: 10px;}
     .word{color: #333;margin-top: 8px;opacity: 0.8;text-align: center;}
     .img{width: 42px;height: 42px;}    
}
.van-popup{background: rgba(255,255,255,0.8);}
#more{ .cancle{padding: 12px 0;font-size: 16px;background: #fff;text-align: center;margin-top: 20px;}}
</style>